﻿using Entitas.Unity;
using UnityEngine;

public abstract class UnityObject : MonoBehaviour, IViewObject
{
    protected GameEntity _linkedEntity;

    public virtual void Link(GameEntity gameEntity)
    {
        _linkedEntity = gameEntity;
        gameObject.Link(gameEntity);
        if (_linkedEntity.hasTransform)
        {
            gameObject.transform.position = _linkedEntity.transform.position;
        }
    }

    public virtual void Unlink()
    {
        gameObject.Unlink();
        Destroy(gameObject);
    }
}